home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Computer Select (Limited Edition)
/
Computer Select.iso
/
pcc
/
v04n09
/
timer.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-01-02
|
2KB
|
83 lines
/*
** TIMER.C
**
** Program to wait a specified number of minutes
** (tabstops=4)
**
** Written for my buddy THR by SCB on 1/2/90
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
#include <dos.h>
void main (
int argc,
char *argv[]
)
{
register int i; /* busy ticker index */
double d; /* work double */
clock_t ticks; /* target tick count */
time_t now; /* current time */
int rc; /* return code */
static char busy[] = "/\304\\\263"; /* busy ticker characters */
if (argc != 2) { /* pretty inflexible arguments */
printf("usage: timer <number-of-minutes>\n");
printf(" returns 0=completed, 1=aborted, 2=error\n");
exit(2);
}
if ((ticks = (clock_t)atoi(argv[1])) <= 0) { /* can't go backwards */
printf("number-of-minutes must be > 0\n");
exit(2);
}
/* dedication */
printf("\304\304\264 For THR from SCB \303\304\304\n");
d = (double)ticks * 60.0 * CLK_TCK; /* number of ticks */
time(&now); /* output current time */
printf("\n%s\n",ctime(&now));
printf("Delaying %ld minute%s ... press ESCape to abort ",
(long)ticks,(ticks == 1? "": "s"));
ticks = (clock_t)d + clock(); /* target ticks */
rc = 0; /* success return */
i = 0; /* for busy ticker */
/* loop until abort or target time reached */
while (clock() < ticks) {
if (kbhit())
if (getch() == 27) {
rc = 1; /* set aborted return */
break;
}
putchar(busy[i]); /* keep their eyes busy */
putchar('\010');
if (++i == 4) /* advance index */
i = 0;
sleep(1); /* at one second intervals */
}
if (rc) /* inform of abort */
printf(" \nAborted with ESCape");
time(&now);
printf(" \n\n%s",ctime(&now));
exit(rc);
}